﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using DTO;
using BUS;
using System.Resources;
using System.Globalization;
using DevComponents.DotNetBar.Rendering;
namespace QuanLyPhongMach
{
    public partial class PhongMach : DevComponents.DotNetBar.Metro.MetroForm
    {
        public PhongMach()
        {
            InitializeComponent();
            RibbonPredefinedColorSchemes.ChangeOffice2007ColorTable(eOffice2007ColorScheme.Silver);
            LoadDanhSachBenhNhan();
        }
        DataTable dtProgress = new DataTable();
        private void LoadDanhSachBenhNhan()
        {
            timer1.Start();
            dtProgress = BenhNhan_BUS.DanhSachBenhNhan();
            foreach (DataRow dr in dtProgress.Rows)
            {
                timer1.Enabled = true;
            }
        }
        private void bubbleButton1_Click(object sender, ClickEventArgs e)
        {
            frmThemBenhNhan frThem = new frmThemBenhNhan();
            frThem.KhiThemMoi += fr_KhiThemMoi;
            frThem.ShowDialog();
        }
        void fr_KhiThemMoi()
        {
            dgvBenhNhan.DataSource = LayBenhNhan();
        }
        public DataTable LayBenhNhan()
        {
            DataTable dt = BenhNhan_BUS.DanhSachBenhNhan();
            return dt;
        }

        private void dgvBenhNhan_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            dgvBenhNhan.Rows[e.RowIndex].Cells["STT"].Value = e.RowIndex + 1;
        }

    
        private void dgvBenhNhan_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            frmPhienKham pk = new frmPhienKham();
            pk.MaBN = dgvBenhNhan.CurrentRow.Cells["MaBN"].Value.ToString();
            pk.KhiSua += fr_KhiThemMoi;
            pk.KhiXoa += fr_KhiThemMoi;
            pk.Show();
        }
       


        private void PhongMach_Load(object sender, EventArgs e)
        {
            lblTenNhanVien.Text = ThongTinDangNhap.Ten;
        }

        private void txtTenBenhNhan_Click(object sender, EventArgs e)
        {
            txtTenBenhNhan.Text = "";
        }

        private void txtDiaChi_Click(object sender, EventArgs e)
        {
            txtDiaChi.Text = "";
        }

        private void txtTenBenhNhan_TextChanged(object sender, EventArgs e)
        {
            circularProgress1.Value = 0;
            dtProgress = new DataTable();
            dtProgress = BenhNhan_BUS.DanhSachBenhNhanTheoTen(txtTenBenhNhan.Text);
            foreach (DataRow dr in dtProgress.Rows)
            {
                timer1.Enabled = true;
                circularProgress1.Enabled = true;
                dgvBenhNhan.DataSource = null;
                circularProgress1.Show();
            }                   
        }

        private void txtDiaChi_TextChanged(object sender, EventArgs e)
        {

            circularProgress1.Value = 0;
            dtProgress = new DataTable();
            dtProgress = BenhNhan_BUS.DanhSachBenhNhanTheoDiaChi(txtDiaChi.Text);
            foreach (DataRow dr in dtProgress.Rows)
            {
                timer1.Enabled = true;
                circularProgress1.Enabled = true;
                dgvBenhNhan.DataSource = null;
                circularProgress1.Show();
            }   
        }

        private void bubbleButton2_Click(object sender, ClickEventArgs e)
        {
            try
            {
                string ma = dgvBenhNhan.CurrentRow.Cells["MaBN"].Value.ToString();
                if (ma == "")
                {
                    MessageBox.Show("Vui lòng chọn hồ sơ");
                }
                else
                {
                    if (MessageBox.Show("Bạn thực sự muốn xóa không", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        if (BenhNhan_BUS.XoaBenhNhan(ma) == true)
                        {
                            MessageBox.Show("Xóa thành công");
                            LoadDanhSachBenhNhan();
                        }
                        else
                        {
                            MessageBox.Show("Xóa thất bại");
                        }
                    }
                }
            }
            catch (Exception ex)
            { }
        }

        private void btnDen_Click(object sender, EventArgs e)
        {
            RibbonPredefinedColorSchemes.ChangeOffice2007ColorTable(eOffice2007ColorScheme.Black);
        }
        private void btnXanh_Click(object sender, EventArgs e)
        {
            RibbonPredefinedColorSchemes.ChangeOffice2007ColorTable(eOffice2007ColorScheme.Blue);
        }

        

        private void PhongMach_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            circularProgress1.Value = Convert.ToInt32(circularProgress1.Value)+ 10;
            if (Convert.ToInt32(circularProgress1.Value) > 90)
            {
                timer1.Enabled = false;
                circularProgress1.Enabled = false;
                dgvBenhNhan.AutoGenerateColumns = false;
                dgvBenhNhan.DataSource = dtProgress;
                circularProgress1.Hide();
            }
            
        }

        private void metroTileItem2_Click(object sender, EventArgs e)
        {
            QuanLyNhanVien ql = new QuanLyNhanVien();
            ql.Show();
        }

        CultureInfo culture;
        private void SetLanguage(string cultureName)
        {
            culture = CultureInfo.CreateSpecificCulture(cultureName);
            ResourceManager rm = new
                ResourceManager("QuanLyPhongMach.Language.MyResource", typeof(PhongMach).Assembly);
            lblNgonNgu.Text = rm.GetString("Language", culture);
            txtDiaChi.Text = rm.GetString("Address", culture);
            DiaChi.HeaderText = rm.GetString("Address", culture);
            TenBN.HeaderText = rm.GetString("Patient Name", culture);
            txtTenBenhNhan.Text = rm.GetString("Patient Name", culture);
            SoDienThoai.HeaderText = rm.GetString("Phone", culture);
            NgheNghiep.HeaderText = rm.GetString("Job", culture);
            NgaySinh.HeaderText = rm.GetString("BirthDay", culture);
            btnDen.Text = rm.GetString("Black", culture);
            btnXanh.Text = rm.GetString("Blue", culture);
            metroTileItem2.Text = rm.GetString("Manage Staff", culture);
            metroTileItem3.Text = rm.GetString("Manage Drug", culture);
            grPhienKham.Text = rm.GetString("Search examination session", culture);
            bubbleButton1.TooltipText = rm.GetString("AddPatientrRecord", culture);
            lblTenNV.Text = rm.GetString("Staffs", culture);
            superTabItem2.Text = rm.GetString("clinic information", culture);
            superTabItem1.Text = rm.GetString("patient records", culture);
          
        }

        public static bool bLanguage = true;

        private void switchButton1_Click(object sender, EventArgs e)
        {
            if (switchButton1.Value == true)
            {
                SetLanguage("vi-VN");
                bLanguage = true;
            }
            else
            {
                SetLanguage("en-US");
                bLanguage = false;
            }
               
        }

        private void metroTileItem3_Click(object sender, EventArgs e)
        {
            QuanLyThuocDichVu frmThuoc = new QuanLyThuocDichVu();
            frmThuoc.Show();
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            SetLanguage("en-US");
        }

     


        


    }
}